package net.betou.trade.entity.main.base;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import net.betou.trade.entity.main.AgentAndAdmins;
import net.betou.trade.entity.main.Role;
import net.betou.trade.entity.main.RoleExt;

/**
 * 角色 "table: trade_role"
 * @author 叶装装
 * 
 */
public abstract class BaseRole implements Serializable{
	
	private Integer id;
	private String name;          // 角色名称
	private String description; // 描述信息
	private Date createTime; // 创建时间
	private Integer level; // 角色等级主要用来区分添加居间管理员的时候可以指定那些角色
	private Boolean manager; // 是否是管理分组, 0 为居间商管理分组， 1 为系统管理分组
	private Boolean roleDefault; // 是否是默认的, 0为否,1为是, 默认将不能进行删除或者更新操作, 当然这只对应于系统管理角色
	private Boolean allowInit; // 是否允许初始化角色，如果是的话，在添加机构或者代理商的时候，将会初始化这些默认的列表
	
	private AgentAndAdmins admin; // many to one  该角色所属的管理员，可以为空，对系统角色不起作用
	
	private String identity; // 标识符, 主要来区分添加时候的默认方式
	
	private Boolean allowRead; // 是否允许读取， 指的是在添加系统管理员的时候是否允许被读取出来, 默认为是

	private Set< RoleExt > roleExt; // one to many
	
	private Set< String > perms;
	
	private Set< String > shares;
	
	
	public BaseRole( ) {
		initialize( );
	}

	public BaseRole( Integer id ) {
		this.id = id;
		initialize( );
		this.hashCode = Integer.MIN_VALUE;
	}

	public BaseRole( Integer id, String name, String description, Date createTime, Set< String > perms ) {
		super( );
		this.id = id;
		this.name = name;
		this.description = description;
		this.createTime = createTime;
		this.perms = perms;
		
		initialize( );
	}

	protected void initialize( ) {
	}

	private int hashCode = Integer.MIN_VALUE;

	public boolean equals( Object obj ) {
		if( null == obj )
			return false;
		if( !( obj instanceof Role ) )
			return false;
		else{
			Role role = ( Role ) obj;
			if( null == this.getId( ) || null == role.getId( ) )
				return false;
			else
				return( this.getId( ).equals( role.getId( ) ) );
		}
	}

	public int hashCode( ) {
		if( Integer.MIN_VALUE == this.hashCode ){
			if( null == this.getId( ) )
				return super.hashCode( );
			else{
				String hashStr = this.getClass( ).getName( ) + ":" + this.getId( ).hashCode( );
				this.hashCode = hashStr.hashCode( );
			}
		}
		return this.hashCode;
	}

	public Integer getId( ) {
		return id;
	}

	public void setId( Integer id ) {
		this.id = id;
		this.hashCode = Integer.MIN_VALUE;
	}

	public String getName( ) {
		return name;
	}

	public void setName( String name ) {
		this.name = name;
	}

	public String getDescription( ) {
		return description;
	}

	public void setDescription( String description ) {
		this.description = description;
	}

	public Date getCreateTime( ) {
		return createTime;
	}

	public void setCreateTime( Date createTime ) {
		this.createTime = createTime;
	}

	public java.util.Set< String > getPerms( ) {
		return perms;
	}

	public void setPerms( java.util.Set< String > perms ) {
		this.perms = perms;
	}
	
	public Integer getLevel( ) {
		return level;
	}

	public void setLevel( Integer level ) {
		this.level = level;
	}

	public Boolean getManager( ) {
		return manager;
	}

	public void setManager( Boolean manager ) {
		this.manager = manager;
	}
	
	public Set< RoleExt > getRoleExt( ) {
		return roleExt;
	}

	public void setRoleExt( Set< RoleExt > roleExt ) {
		this.roleExt = roleExt;
	}

	public Boolean getRoleDefault( ) {
		return roleDefault;
	}

	public void setRoleDefault( Boolean roleDefault ) {
		this.roleDefault = roleDefault;
	}
	
	public AgentAndAdmins getAdmin( ) {
		return admin;
	}

	public void setAdmin( AgentAndAdmins admin ) {
		this.admin = admin;
	}

	
	public String getIdentity( ) {
		return identity;
	}

	public void setIdentity( String identity ) {
		this.identity = identity;
	}

	public Boolean getAllowRead( ) {
		return allowRead;
	}

	public void setAllowRead( Boolean allowRead ) {
		this.allowRead = allowRead;
	}
	

	public Boolean getAllowInit( ) {
		return allowInit;
	}

	public void setAllowInit( Boolean allowInit ) {
		this.allowInit = allowInit;
	}

	public Set< String > getShares( ) {
		return shares;
	}

	public void setShares( Set< String > shares ) {
		this.shares = shares;
	}

	private static final long serialVersionUID = -2132060290795387407L;
}
